const path = require("path");
const webpack = require("webpack");

const UglifyJSPlugin = require("uglifyjs-webpack-plugin");
const AssetsPlugin = require("assets-webpack-plugin");
const CleanWebpackPlugin = require("clean-webpack-plugin");

const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;

const DIST = path.resolve(__dirname, "dist");

const vendors = [
    "vue",
    "vue-router",
    "iview",
    "axios",
    "date-format-lite"
];

module.exports = {
    entry: {
        vendors: vendors
    },
    output: {
        path: DIST,
        filename: "[name].[chunkhash].js",
        library: "[name]_[chunkhash]"
    },
    plugins: [
        new CleanWebpackPlugin(["dist/vendors.*.js"]),
        new webpack.DllPlugin({
            path: DIST + "/temp/vendors.manifest.json",
            name: "[name]_[chunkhash]",
            context: __dirname,
        }),
        new UglifyJSPlugin({
            cache: true,
            parallel: true,
            sourceMap: false, //default false
            uglifyOptions: {
                ecma: 8,
                warnings: false // default false
            }
        }),
        new AssetsPlugin({
            filename: "temp/vendors.assets.json",
            path: DIST
        }),
        new BundleAnalyzerPlugin({
            analyzerMode: "static",
            reportFilename: "temp/vendors.report.html"
        })
    ]
};
